* Import hospitalized COVID-19 on cases and dead.

/* Note: file uses highly disaggregated data.
For data privacy reasons the data is only made available in the aggregated form & the preparation is skipped */

use "$raw/goeg_cases_dead", clear

rename gkz municipality_id
rename nc daily_cases
rename nd daily_deaths

recode municipality_id (61709 60649 60650 = 61758) /// Fladnitz an der Teichalm
	(61723 61755 = 61766) /// Weiz
	(40803 40819 = 40835) /// Peuerbach
	(60327 60336 = 60347) /// Stankt Martin im Sulmtal 
	(60607 60614 60616 60622 = 60664) /// Gratwein-Straßengel
	(60409 = 62314) /// Eichkögl see https://www.landesentwicklung.steiermark.at/cms/dokumente/12658686_141979478/84d9aa6e/Zusammenlegung%20FB_RA.pdf
	(61901 = 61254) /// (Municipality Aich) these allocations are from Josef Holzer (Statistics Styria)
	(61904 = 61213) ///  (Municipality Gröbming)
	(61905 = 61217) ///  (Municipality Haus)
	(61910 = 61262) ///  (Municipality Öblarn)
	(61913 = 61236) ///  (Municipality Ramsau am Dachstein)
	(61917 = 61265) ///  (Municipality Schladming)
	
	
collapse (sum) daily_cases daily_deaths, by(municipality_id date)
	
sort municipality_id date

by municipality_id (date): gen cum_cases = sum(daily_cases)
by municipality_id (date): gen cum_deaths = sum(daily_deaths)
	
lab var daily_cases "Daily cases"
lab var daily_deaths "Daily deaths"
lab var cum_cases "Cumulative cases"
lab var cum_deaths "Cumulative deaths"

foreach var in cases deaths {
	foreach date in 27dec2020 03dec2021 {
		gen cum_`var'_`date' = cum_`var' if date==td(`date')
		bysort municipality_id (cum_`var'_`date'): replace cum_`var'_`date' = cum_`var'_`date'[1]
	}
	gen `var'_post = cum_`var'_03dec2021 - cum_`var'_27dec2020
}

lab var cum_cases_27dec2020 "Pre-treatment cases"
lab var cum_cases_03dec2021 "Cases until 03Dec2021"
lab var cases_post "Post-treatment cases"

lab var cum_deaths_27dec2020 "Pre-treatment deaths"
lab var cum_deaths_03dec2021 "Deaths until 03Dec2021"
lab var deaths_post "Post-treatment deaths"

* used for aggregation
keep if date==22500
keep municipality_id cum_cases_27dec2020 cum_deaths_27dec2020 

save "$edited/goeg_cases_dead.dta", replace

